<?php
/**
 * Author  : zxz
 * Datetime: 2019/3/17 下午7:09
 */

namespace Xy\Rbac\Controllers;


use Illuminate\Http\Request;
use Illuminate\Routing\Controller;
use Xy\Rbac\Requests\RbacRoleFormStoreRequest;
use Xy\Rbac\Requests\RbacRoleFormUpdateRequest;
use Xy\Rbac\Services\RbacRoleService;

class RbacRoleController extends Controller {
    protected $_rbacRoleService;
    
    public function __construct(RbacRoleService $adminRoleService) {
        $this->_rbacRoleService = $adminRoleService;
    }
    
    /**
     * @return array
     */
    public function getPage() {
        return $this->_rbacRoleService->getPage();
    }
    
    /**
     * @return \Illuminate\Database\Eloquent\Builder[]|\Illuminate\Database\Eloquent\Collection
     */
    public function index() {
        return $this->_rbacRoleService->getAllRbacRole();
    }
    
    /**
     * @param Request $request
     *
     * @return mixed
     */
    public function store(RbacRoleFormStoreRequest $request) {
        return $this->_rbacRoleService->storeRbacRole($request);
    }
    
    /**
     * @param Request $request
     * @param         $id
     *
     * @return \Illuminate\Database\Eloquent\Builder|\Illuminate\Database\Eloquent\Builder[]|\Illuminate\Database\Eloquent\Collection|\Illuminate\Database\Eloquent\Model|null
     * @throws \Exception
     */
    public function update(RbacRoleFormUpdateRequest $request, $id) {
        return $this->_rbacRoleService->updateRbacRole($id, $request);
    }
    
    /**
     * @param $id
     *
     * @return array
     * @throws \Exception
     */
    public function destroy($id) {
        return $this->_rbacRoleService->destroyRbacRole($id);
    }
    
    /**
     * 分配页面权限给角色
     *
     * @param Request $request
     * @param         $id
     *
     * @return mixed
     */
    public function assignRolePowerPage(Request $request, $id) {
        return $this->_rbacRoleService->assignRolePowerPage($id, $request);
    }
}